package GUIs;

import Configs.Config;
import Controllers.ChuNhaTroController;
import javax.swing.JOptionPane;

public class f_nhanvien_chunhatro_them extends javax.swing.JFrame {

    private static f_nhanvien_chunhatro_them _instance; //Kiểm tra sự tồn tại của 2 instance trong cùng 1 form
    private final Config conn;
    private final ChuNhaTroController chunhatrocontrol;

    public f_nhanvien_chunhatro_them(Config conn) {
        this.conn = conn;
        this.chunhatrocontrol = new ChuNhaTroController(this.conn);
        initComponents();
    }

    public static f_nhanvien_chunhatro_them getInstance(Config conn) {
        if (_instance == null) {
            _instance = new f_nhanvien_chunhatro_them(conn);
        }
        return _instance;
    }

    public void createAndShowUI() {
        setVisible(true);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnchinh = new javax.swing.JPanel();
        tftinhtp = new javax.swing.JTextField();
        lbtinhtp = new javax.swing.JLabel();
        tfquanhuyen = new javax.swing.JTextField();
        lbquanhuyen = new javax.swing.JLabel();
        tfduong = new javax.swing.JTextField();
        lbduong = new javax.swing.JLabel();
        tfhem = new javax.swing.JTextField();
        lbhem = new javax.swing.JLabel();
        tfsonha = new javax.swing.JTextField();
        lbsonha = new javax.swing.JLabel();
        tfsdt = new javax.swing.JTextField();
        lbsdt = new javax.swing.JLabel();
        cbbgioitinh = new javax.swing.JComboBox();
        lbgioitinh = new javax.swing.JLabel();
        datengaysinh = new org.jdesktop.swingx.JXDatePicker();
        lbngaysinh = new javax.swing.JLabel();
        tfcmnd = new javax.swing.JTextField();
        lbcmnd = new javax.swing.JLabel();
        tfhoten = new javax.swing.JTextField();
        lbchunhatro = new javax.swing.JLabel();
        btnluulai = new javax.swing.JButton();
        btnlamlai = new javax.swing.JButton();
        btnthoat = new javax.swing.JButton();
        lbtieude = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Thêm chủ nhà trọ");
        setResizable(false);
        setType(java.awt.Window.Type.UTILITY);

        lbtinhtp.setText("Tỉnh/TP:");

        lbquanhuyen.setText("Quận/Huyện:");

        lbduong.setText("Đường:");

        lbhem.setText("Hẻm:");

        lbsonha.setText("Số nhà:");

        lbsdt.setText("Số điện thoại:");

        cbbgioitinh.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Chọn", "Nam", "Nữ" }));

        lbgioitinh.setText("Giới tính:");

        this.datengaysinh.setDate(new java.util.Date(714718800000L));

        lbngaysinh.setText("Ngày sinh:");

        lbcmnd.setText("CMND:");

        lbchunhatro.setText("Họ và tên:");

        btnluulai.setText("Lưu lại");
        btnluulai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnluulaiActionPerformed(evt);
            }
        });

        btnlamlai.setText("Làm lại");
        btnlamlai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnlamlaiActionPerformed(evt);
            }
        });

        btnthoat.setText("Thoát");
        btnthoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnthoatActionPerformed(evt);
            }
        });

        lbtieude.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbtieude.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbtieude.setText("Thêm chủ nhà trọ");

        javax.swing.GroupLayout pnchinhLayout = new javax.swing.GroupLayout(pnchinh);
        pnchinh.setLayout(pnchinhLayout);
        pnchinhLayout.setHorizontalGroup(
            pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lbtieude, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnchinhLayout.createSequentialGroup()
                .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnchinhLayout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(lbngaysinh)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(datengaysinh, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnchinhLayout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnchinhLayout.createSequentialGroup()
                                .addComponent(lbsonha)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tfsonha, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnchinhLayout.createSequentialGroup()
                                .addComponent(lbgioitinh)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(cbbgioitinh, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnchinhLayout.createSequentialGroup()
                                .addComponent(lbsdt)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 68, Short.MAX_VALUE)
                                .addComponent(tfsdt, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnchinhLayout.createSequentialGroup()
                                .addComponent(lbchunhatro)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
                                .addComponent(tfhoten, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnchinhLayout.createSequentialGroup()
                                .addComponent(lbcmnd)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tfcmnd, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnchinhLayout.createSequentialGroup()
                                .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbduong)
                                    .addComponent(lbhem)
                                    .addComponent(lbquanhuyen)
                                    .addComponent(lbtinhtp))
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addGap(47, 47, 47))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnchinhLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(btnluulai)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnlamlai)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnthoat)
                .addGap(81, 81, 81))
            .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnchinhLayout.createSequentialGroup()
                    .addGap(175, 175, 175)
                    .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(tfquanhuyen, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tftinhtp, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tfhem)
                            .addComponent(tfduong, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(45, Short.MAX_VALUE)))
        );
        pnchinhLayout.setVerticalGroup(
            pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnchinhLayout.createSequentialGroup()
                .addComponent(lbtieude, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbcmnd)
                    .addComponent(tfcmnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfhoten, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbchunhatro))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(datengaysinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbngaysinh))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbbgioitinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbgioitinh))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbsdt)
                    .addComponent(tfsdt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfsonha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbsonha))
                .addGap(18, 18, 18)
                .addComponent(lbhem)
                .addGap(25, 25, 25)
                .addComponent(lbduong)
                .addGap(32, 32, 32)
                .addComponent(lbquanhuyen)
                .addGap(18, 18, 18)
                .addComponent(lbtinhtp)
                .addGap(50, 50, 50)
                .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnluulai)
                    .addComponent(btnlamlai)
                    .addComponent(btnthoat))
                .addContainerGap())
            .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnchinhLayout.createSequentialGroup()
                    .addGap(243, 243, 243)
                    .addComponent(tfhem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(17, 17, 17)
                    .addComponent(tfduong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(tfquanhuyen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(tftinhtp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnchinh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnchinh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void btnluulaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnluulaiActionPerformed
        if (this.chunhatrocontrol.Add(this)) {
            f_nhanvien change = f_nhanvien.getInstance(this.conn, null);
            change.refreshChuNhaTro();
            int dialogResult = JOptionPane.showConfirmDialog(this, "Thêm mới chủ nhà trọ thành công! \nBạn có muốn tiếp tục thêm?\nNhấn yes để tiếp tục, no để thoát khung thêm.", "Warning", JOptionPane.YES_NO_OPTION);
            this.clearform();
            if (dialogResult == JOptionPane.NO_OPTION) {
                this.dispose();
            }
        }
    }//GEN-LAST:event_btnluulaiActionPerformed

    private void btnlamlaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnlamlaiActionPerformed
        this.clearform();
    }//GEN-LAST:event_btnlamlaiActionPerformed

    private void btnthoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnthoatActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnthoatActionPerformed

    private void clearform() {
        this.tfcmnd.setText(null);
        this.tfcmnd.requestFocus();
        this.tfhoten.setText(null);
        this.datengaysinh.setDate(new java.util.Date(714718800000L));
        this.cbbgioitinh.setSelectedIndex(0);
        this.tfsdt.setText(null);
        this.tfsonha.setText(null);
        this.tfhem.setText(null);
        this.tfduong.setText(null);
        this.tfquanhuyen.setText(null);
        this.tftinhtp.setText(null);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnlamlai;
    private javax.swing.JButton btnluulai;
    private javax.swing.JButton btnthoat;
    public javax.swing.JComboBox cbbgioitinh;
    public org.jdesktop.swingx.JXDatePicker datengaysinh;
    private javax.swing.JLabel lbchunhatro;
    private javax.swing.JLabel lbcmnd;
    private javax.swing.JLabel lbduong;
    private javax.swing.JLabel lbgioitinh;
    private javax.swing.JLabel lbhem;
    private javax.swing.JLabel lbngaysinh;
    private javax.swing.JLabel lbquanhuyen;
    private javax.swing.JLabel lbsdt;
    private javax.swing.JLabel lbsonha;
    private javax.swing.JLabel lbtieude;
    private javax.swing.JLabel lbtinhtp;
    private javax.swing.JPanel pnchinh;
    public javax.swing.JTextField tfcmnd;
    public javax.swing.JTextField tfduong;
    public javax.swing.JTextField tfhem;
    public javax.swing.JTextField tfhoten;
    public javax.swing.JTextField tfquanhuyen;
    public javax.swing.JTextField tfsdt;
    public javax.swing.JTextField tfsonha;
    public javax.swing.JTextField tftinhtp;
    // End of variables declaration//GEN-END:variables
}
